package design.patterns.observe;

import java.util.ArrayList;
import java.util.List;

/**
 * @author daxue0929
 * @date 2023/4/25
 */

public class SubscriptionSubject implements Subject {

    //定义一个集合用于存储多个观察者对象

    private List<Observer> weiXinUserList = new ArrayList<>();

    @Override
    public void attach(Observer observer) {
        weiXinUserList.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        weiXinUserList.remove(observer);
    }

    @Override
    public void notify(String message) {
        weiXinUserList.forEach(observer -> observer.update(message));

    }
}
